package com.yixuan.mt.common.service.impl;

import com.yixuan.mt.common.exception.HttpBadRequestException;
import com.yixuan.mt.common.properties.GlobalProperties;
import com.yixuan.mt.common.request.LoginRequest;
import com.yixuan.mt.common.utitls.AdminTokenUtils;
import com.yixuan.mt.common.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class AuthServiceImpl implements AuthService {

    @Autowired
    GlobalProperties globalProperties;

    @Override
    public String login(LoginRequest loginRequest) {
        if (!loginRequest.getUsername().equals(globalProperties.getAdminDefaultUsername()) || !loginRequest.getPassword().equals(globalProperties.getAdminDefaultPassword())) {
            throw new HttpBadRequestException("账号或密码错误！");
        }
        Map<String, Object> map = new HashMap<>();
        map.put("access", "*");
        return AdminTokenUtils.generateJwt(map);
    }
}
